﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using Numbers;

namespace t_Numbers
{
    [TestClass]
    public class t_Alpha_12
    {
        FlavorSample f1num, f2num, f1denom, f2denom;
        epsilon_12 e1, e2;
        Alpha_12 a12;

        [TestInitialize]
        public void CommonCreate()
        {
            f1num = new FlavorSample();
            f1denom = new FlavorSample();
            f2num = new FlavorSample();
            f2denom = new FlavorSample();

            e1 = new epsilon_12(f1num, f2denom);
            e2 = new epsilon_12(f2num, f2denom);
            a12 = new Alpha_12(e1, e2);
        }

        [TestMethod]
        public void TestCTor()
        {
            /// Empty because everything happen above.
        }

        [TestMethod]
        public void TestCalc()
        {
            f1num.Charm = 100;
            f1denom.Charm = 200;

            f2num.Charm = 100;
            f2denom.Charm = 200;

            Assert.AreEqual(1.0, a12.Value, "Expecting the values to be the same!");

            f2num.Charm = 200;
            Assert.AreEqual(0.5, a12.Value, "Expecting a half after resetting the inputs!");
        }

        [TestMethod]
        public void TestChangeNotification()
        {
            int count = 0;
            a12.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler((o, args) =>
            {
                Assert.AreEqual("Value", args.PropertyName, "Property name being changed is right!");
                count += 1;
            });

            f1num.Charm = 100;
            f1denom.Charm = 200;

            f2num.Charm = 100;
            f2denom.Charm = 200;

            count = 0;
            f2num.Charm = 200;
            Assert.AreEqual(1, count, "expected property changed to have fired just once!");
        }

        [TestMethod]
        public void TestInitialResult()
        {
            FlavorSample f1num, f2num, f1denom, f2denom;
            epsilon_12 e1, e2;
            Alpha_12 a12;

            f1num = new FlavorSample();
            f1denom = new FlavorSample();
            f2num = new FlavorSample();
            f2denom = new FlavorSample();

            f1num.Charm = 100;
            f1denom.Charm = 200;
            f2num.Charm = 100;
            f2denom.Charm = 200;

            e1 = new epsilon_12(f1num, f2denom);
            e2 = new epsilon_12(f2num, f2denom);
            a12 = new Alpha_12(e1, e2);

            Assert.AreEqual(1.0, a12.Value, "Initial value is not correct!");
        }

        [TestMethod]
        public void TestDivideByZero()
        {
            Assert.AreEqual(0.0, a12.Value, "Initial value with zero should be... zero!");
        }
    }
}